<?php
/* SVN FILE: $Id: app_controller.php 33 2010-01-12 15:15:16Z gigapromoters $ */
/**
 * @mainpage End-User Manual
 * 
 * <center>
 * @image html home.png
 * </center>
 * 
 * 
 * @section intro Introduction to Crowd Vox
 * 
 * Crowd Vox is a script that anybody can use in order to build a community review website, with a minimum of fuss and a maximum of efficacy.
 * You can also use it as a CMS for any customized requirement.
 * 
 * 
 * @section getting_started Getting started
 * 
 * Getting started is simple, For your convenience we have divided the documentation under 
 * following pages:
 * 
 * @li @subpage installation
 * @li @subpage configuration
 * @li @subpage theme_customization
 * @li @subpage features
 * @li @subpage managing_content
 * @li @subpage addons
 * @li @subpage misc_features
 * @li @subpage tips_tricks
 * 
 * 
 * @section support Get Support
 * 
 * For support queries, please contact us at 
 * <a href="mailto:support@crowdvox.com">support@crowdvox.com</a> 
 * 
 * @author Abhimanyu Grover
 * 
 * @page features Core Features
 * 
 * @li @subpage custom_fields_setup 
 * @li @subpage module_system
 * @li @subpage dynamic_pages
 * 
 */
/**
 * @page misc_features Miscellaneous Features
 * 
 * @li @subpage compare_listings
 * @li @subpage rich_snippets
 * 
 */
/**
 * @page addons Addons
 * 
 * These are some features which are available at some extra cost on our site. In future we'll also
 * release the addons which would be free of cost. If an addon is paid, then you need to buy it from
 * <a href="http://crowdvox.com">our site</a>. Once you purchase it, you will need to enter the license
 * info at Backend > Settings > Licenses
 *
 * 
 * @li @subpage facebook_connect
 * @li @subpage geomap
 * 
 */
/**
 * @page tips_tricks Tips and Tricks
 * 
 * @li @subpage perform_migration
 * 
 */

/**
 * @page managing_content Managing %Content
 * 
 * Managing %Listing, %Reviews, %Review Comments, Categories, Gallery comments and Static pages is pretty
 * self-explanatory. You can manage all these from backend under Managing %Content.
 * 
 * Also refer to @ref listing_type 
 * 
 * This section contains these subsections:
 * @subpage managing_ads
 * 
 */
 require_once(APP.'plugins'.DS.'cms'.DS.'giga_app_controller.php');

class AppController extends GigaAppController {

	//admin_bulkDelete,admin_bulkPublish,admin_bulkUnpublish
	protected $autoAdminActions = array();
	function beforeFilter()
	{
		$this->helpers[] = 'Form';
		$this->helpers[] = 'Modules.Section';
		$this->helpers[] = 'Tags.Tags';
		$this->helpers[] = 'Rating.Rating';
		//@todo (1.1)remove vote helper from here.
		if(cr('cmsInstalled'))
			$this->helpers[] = 'Votes.Vote';
		$this->helpers[] = 'Users.UserContent';
		$this->helpers[] = 'Time';
		$this->helpers[] = 'ListingInformation';
		
		App::import('Vendor', 'Cms.EventManager');
		require_once(APP.'vendors'.DS.'mailer.php');
		$mailer = new AppMailer;
		EventManager::addListener($mailer, 'model');
		
		parent::beforeFilter();
	}
	
	function admin_bulkDelete()
	{
		if(cr('demoMode') === true)
		{
			$this->errorMsg(cr("restrictedActionErrorMessage"));
			$this->redirect($this->referer());
			return;
		}
		if(!in_array(__FUNCTION__,$this->autoAdminActions))
		{
			$this->errorMsg("Invalid action");
			$this->redirect($this->referer());
			return;
		}
		$Model = $this->{$this->modelNames[0]};
		if($Model)
		{
			$ids = $this->data[$Model->alias]['ids'];
			$ids = explode(";",$ids);
			$ids = Set::filter($ids);
			if(count($ids))
			{
				foreach($ids as $id)
				{
					$Model->delete($id);
				}
			}
			$this->successMsg(sprintf(__("%s has been deleted"),$Model->getFrontendName()."(s)"));
		}
		$this->redirect($this->referer());
		
	}
	
	function admin_bulkPublish()
	{
		if(!in_array(__FUNCTION__,$this->autoAdminActions))
		{
			$this->errorMsg("Invalid action");
			$this->redirect($this->referer());
			return;
		}
		$Model = $this->{$this->modelNames[0]};
		if($Model)
		{
			$ids = $this->data[$Model->alias]['ids'];
			$ids = explode(";",$ids);
			$ids = Set::filter($ids);
			if(count($ids))
			{
				foreach($ids as $id)
				{
					$Model->id = $id;
					$Model->saveField("status",1);
				}
			}
			$this->successMsg(sprintf(__("%s has been published"),$Model->getFrontendName()."(s)"));
		}
		$this->redirect($this->referer());
	}
	
	function admin_bulkUnpublish()
	{
		if(!in_array(__FUNCTION__,$this->autoAdminActions))
		{
			$this->errorMsg("Invalid action");
			$this->redirect($this->referer());
			return;
		}
		$Model = $this->{$this->modelNames[0]};
		if($Model)
		{
			$ids = $this->data[$Model->alias]['ids'];
			$ids = explode(";",$ids);
			$ids = Set::filter($ids);
			if(count($ids))
			{
				foreach($ids as $id)
				{
					$Model->id = $id;
					$Model->saveField("status",0);
				}
			}
			$this->successMsg(sprintf(__("%s has been unpublished"),$Model->getFrontendName()."(s)"));
		}
		$this->redirect($this->referer());
	}
}
?>